package com.cn.topAndFoot.controller;

import com.cn.common.pojo.ResultModel;
import com.cn.common.pojo.TopModel;
import com.cn.topAndFoot.service.TopService;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@Api(tags = "top信息")
@RestController
@RequestMapping("top")
public class TopController {
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String date= DATE_FORMAT.format(new Date());
//    @Autowired
//    RedisService redisService;
    @Autowired
    TopService topService;
//    @GetMapping("top")
//    public ResultModel top(){
//        ResultModel top = redisService.FTop();
////        ResultModel top = topService.top();
//        return top;
//    }
    @GetMapping("delete")
    public ResultModel delete(int id){
        ResultModel delete = topService.delete(id);
        return delete;
    }
    @PostMapping("update")
    public ResultModel update(TopModel topModel){
        ResultModel update = topService.update(topModel);
        return update;
    }
    @PostMapping(value = "insert")
    public ResultModel insert(TopModel topModel){
        ResultModel insert = topService.insert(topModel);
        return insert;
    }
    @PostMapping(value = "enable")
    public ResultModel enable(int id){
        ResultModel enable = topService.enable(id);
        return enable;
    }
    @GetMapping("findById")
    public ResultModel findById(int id){
        ResultModel findById = topService.findById(id);
        return findById;
    }
    @GetMapping("limit")
    public ResultModel limit(TopModel topModel,int limit,int page){
        topModel.setPageNum(page);
        topModel.setPageSize(limit);
        ResultModel resultModel = topService.limit(topModel);
        return resultModel;
    }

    @GetMapping("findAll")
    public ResultModel findAll(int limit,int page){
        ResultModel all = topService.findAll(page,limit);
        return all;
    }
}
